package com.androidx.p013lv.invention.activity;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidx.p013lv.base.bean.AttentionContentBean;
import com.androidx.p013lv.base.bean.InventionThreeBean;
import com.androidx.p013lv.base.bean.StarBean;
import com.androidx.p013lv.base.bean.TwoBean;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.bean.event.AttentionEvent;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.C1069R;
import com.androidx.p013lv.invention.HttpAttention;
import com.androidx.p013lv.invention.adapter.AdapterStarInfo;
import com.androidx.p013lv.invention.databinding.ActivityStarInfoBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import org.greenrobot.eventbus.EventBus;

/* renamed from: com.androidx.lv.invention.activity.StarInfoActivity */
public class StarInfoActivity extends BaseActivity<ActivityStarInfoBinding> implements OnLoadMoreListener {
    String HTTP_CANCEL_TAG = "cancelAttention1";
    String HTTP_SAVE_TAG = "saveAttention1";
    String HTTP_TAG = "queryContentVideo";
    String HTTP_TAG_INFO = "queryContentInfo";
    AdapterStarInfo adapter;
    InventionThreeBean beanInfo;
    HttpCallback<BaseRes<AttentionContentBean>> cancelHttp;
    public int contentId;
    int lastId = 0;
    HttpCallback<BaseRes<AttentionContentBean>> saveHttp;
    public String txt;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1069R.C1074layout.activity_star_info;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        if (TextUtils.isEmpty(this.txt)) {
            ((ActivityStarInfoBinding) this.binding).tvBack.setText("返回");
        } else {
            ((ActivityStarInfoBinding) this.binding).tvBack.setText(this.txt);
        }
        ((ActivityStarInfoBinding) this.binding).refresh.setEnableRefresh(false);
        ((ActivityStarInfoBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ViewGroup.LayoutParams layoutParams = ((ActivityStarInfoBinding) this.binding).ivCover.getLayoutParams();
        layoutParams.height = (int) ((double) ((UiUtils.getWindowWidth() * 277) / 420));
        ((ActivityStarInfoBinding) this.binding).ivCover.setLayoutParams(layoutParams);
        ((ActivityStarInfoBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.View$OnClickListenerC10941 */

            public void onClick(View view) {
                StarInfoActivity.this.finish();
            }
        });
        ((ActivityStarInfoBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(this));
        this.adapter = new AdapterStarInfo();
        ((ActivityStarInfoBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(new ItemClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C10952 */

            @Override // com.androidx.p013lv.base.listener.ItemClickListener
            public void onItemClick(View view, int i) {
                StarInfoActivity starInfoActivity = StarInfoActivity.this;
                starInfoActivity.startVideoPlay(((VideoBean) starInfoActivity.adapter.getDataInPosition(i)).getVideoId());
            }
        });
        ((ActivityStarInfoBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.View$OnClickListenerC10963 */

            public void onClick(View view) {
                StarInfoActivity.this.lastId = 0;
                StarInfoActivity.this.getInfo();
            }
        });
        get();
        getInfo();
        ((ActivityStarInfoBinding) this.binding).scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C10974 */

            @Override // androidx.core.widget.NestedScrollView.OnScrollChangeListener
            public void onScrollChange(NestedScrollView nestedScrollView, int i, int i2, int i3, int i4) {
                if (i2 == 0) {
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).toolbar.setBackground(null);
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvTitle.setVisibility(8);
                    return;
                }
                ((ActivityStarInfoBinding) StarInfoActivity.this.binding).toolbar.setBackgroundResource(C1069R.C1071drawable.shape_invention_tab_bg);
                ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvTitle.setVisibility(0);
            }
        });
        ((ActivityStarInfoBinding) this.binding).llAttention.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.View$OnClickListenerC10985 */

            public void onClick(View view) {
                if (StarInfoActivity.this.beanInfo != null) {
                    if (StarInfoActivity.this.beanInfo.isAttention()) {
                        HttpAttention.getInstance().cancelAttention(StarInfoActivity.this.beanInfo.getContentId(), StarInfoActivity.this.cancelHttp());
                    } else {
                        HttpAttention.getInstance().saveAttention(StarInfoActivity.this.beanInfo.getContentId(), StarInfoActivity.this.saveHttp());
                    }
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void get() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryContentInfo(this.contentId), new HttpCallback<BaseRes<StarBean>>(this.HTTP_TAG_INFO) {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C10996 */

            public void onLvSuccess(BaseRes<StarBean> baseRes) {
                if (baseRes.getCode() == 200 && baseRes.getData() != null && baseRes.getData().getResp() != null) {
                    StarInfoActivity.this.beanInfo = baseRes.getData().getResp();
                    if (StarInfoActivity.this.beanInfo.getSelfImg() == null || TextUtils.isEmpty(StarInfoActivity.this.beanInfo.getSelfImg())) {
                        ((ActivityStarInfoBinding) StarInfoActivity.this.binding).ivCover.setImageResource(C1069R.C1071drawable.base_ic_default);
                    } else {
                        GlideUtils.loadPicWh2(baseRes.getData().getDomain() + StarInfoActivity.this.beanInfo.getSelfImg(), ((ActivityStarInfoBinding) StarInfoActivity.this.binding).ivCover, 600);
                    }
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvTitle.setText(StarInfoActivity.this.beanInfo.getContentName());
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvName.setText(StarInfoActivity.this.beanInfo.getContentName());
                    TextView textView = ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvPlaySum;
                    textView.setText("" + StarInfoActivity.this.beanInfo.getPlayNum());
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).tvInfo.setText(StarInfoActivity.this.beanInfo.getInfo());
                    TextView textView2 = ((ActivityStarInfoBinding) StarInfoActivity.this.binding).btnSum;
                    textView2.setText(StarInfoActivity.this.beanInfo.getVideoNum() + "");
                    StarInfoActivity.this.setAttention();
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setAttention() {
        if (this.beanInfo.isAttention()) {
            ((ActivityStarInfoBinding) this.binding).llAttention.setBackgroundResource(C1069R.C1071drawable.shape_star_info_attention_bg_no);
            ((ActivityStarInfoBinding) this.binding).tvAttention.setText("取消關注");
            ((ActivityStarInfoBinding) this.binding).tvAttention.setCompoundDrawablesWithIntrinsicBounds((Drawable) null, (Drawable) null, (Drawable) null, (Drawable) null);
            return;
        }
        ((ActivityStarInfoBinding) this.binding).llAttention.setBackgroundResource(C1069R.C1071drawable.shape_star_info_attention_bg);
        ((ActivityStarInfoBinding) this.binding).tvAttention.setText("關注");
        ((ActivityStarInfoBinding) this.binding).tvAttention.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(C1069R.C1071drawable.ic_star_info_attention), (Drawable) null, (Drawable) null, (Drawable) null);
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.lastId == 0) {
            AdapterStarInfo adapterStarInfo = this.adapter;
            if (!(adapterStarInfo == null || adapterStarInfo.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((ActivityStarInfoBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((ActivityStarInfoBinding) this.binding).statusLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryContentVideo(this.contentId, this.lastId, 30), new HttpCallback<BaseRes<TwoBean>>(this.HTTP_TAG) {
            /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C11007 */

            public void onLvSuccess(BaseRes<TwoBean> baseRes) {
                ((ActivityStarInfoBinding) StarInfoActivity.this.binding).statusLayout.hideLoading();
                ((ActivityStarInfoBinding) StarInfoActivity.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getList() != null && baseRes.getData().getList().size() > 0) {
                        StarInfoActivity.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (StarInfoActivity.this.lastId == 0) {
                            StarInfoActivity.this.adapter.setData(baseRes.getData().getList());
                            ((ActivityStarInfoBinding) StarInfoActivity.this.binding).refresh.resetNoMoreData();
                            return;
                        }
                        StarInfoActivity.this.adapter.setDatasInEnd(baseRes.getData().getList());
                    } else if (StarInfoActivity.this.lastId == 0) {
                        ((ActivityStarInfoBinding) StarInfoActivity.this.binding).statusLayout.showEmpty();
                    } else {
                        ((ActivityStarInfoBinding) StarInfoActivity.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (StarInfoActivity.this.lastId == 0) {
                    ((ActivityStarInfoBinding) StarInfoActivity.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        AdapterStarInfo adapterStarInfo = this.adapter;
        if (adapterStarInfo == null || adapterStarInfo.getData() == null || this.adapter.getData().size() == 0) {
            ((ActivityStarInfoBinding) this.binding).refresh.finishLoadMore();
            return;
        }
        this.lastId = ((VideoBean) this.adapter.getLastDataInPosition()).getVideoId();
        getInfo();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG_INFO);
        HttpUtils.getInsatance().cancelTag(this.HTTP_CANCEL_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_SAVE_TAG);
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityStarInfoBinding) this.binding).toolbar).init();
    }

    public HttpCallback<BaseRes<AttentionContentBean>> cancelHttp() {
        if (this.cancelHttp == null) {
            this.cancelHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_CANCEL_TAG, this) {
                /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C11018 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        StarInfoActivity.this.beanInfo.setAttention(false);
                        EventBus.getDefault().post(new AttentionEvent(StarInfoActivity.this.beanInfo.getContentId(), false));
                        StarInfoActivity.this.setAttention();
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.cancelHttp;
    }

    public HttpCallback<BaseRes<AttentionContentBean>> saveHttp() {
        if (this.saveHttp == null) {
            this.saveHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_SAVE_TAG, this) {
                /* class com.androidx.p013lv.invention.activity.StarInfoActivity.C11029 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() != 200) {
                        return;
                    }
                    if (baseRes.getCode() == 200) {
                        StarInfoActivity.this.beanInfo.setAttention(true);
                        EventBus.getDefault().post(new AttentionEvent(StarInfoActivity.this.beanInfo.getContentId(), true));
                        StarInfoActivity.this.setAttention();
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.saveHttp;
    }
}
